<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>选择排序</title>
</head>
<body>


<script>
    var arr = [10, 5, 3, 20, 15, 30, 24, 6]

    // 循环获取索引位  为当前索引位找最小值赋值
    for (let i = 0; i < arr.length; i++) {
        // i = 0
        var index = i
        for (var j = i + 1; j < arr.length; j++) {
            if (arr[index] > arr[j]) {
                index = j
            }
        }
        // index 中存储的是 数组中最小值的索引
        if (index != i) {
            var temp = arr[index]
            arr[index] = arr[i]
            arr[i] = temp
        }

    }

    console.log(arr)


</script>
</body>
</html>